{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "249cb54e-4588-5b7d-2c01-60bba33d731e"
      },
      "source": [
        "Simple exploration notebook "
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "50ab2790-3a51-98f3-1e8b-33926c862bfd"
      },
      "outputs": [],
      "source": [
        "# This Python 3 environment comes with many helpful analytics libraries installed\n",
        "# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n",
        "# For example, here's several helpful packages to load in \n",
        "\n",
        "import numpy as np # linear algebra\n",
        "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
        "import matplotlib.pyplot as plt\n",
        "import seaborn as sns\n",
        "from wordcloud import WordCloud\n",
        "from nltk.corpus import stopwords\n",
        "\n",
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "bbda81c2-5282-479c-a931-743437f6d84b"
      },
      "source": [
        "**Wordcloud on tags:**\n",
        "\n",
        "Let us create a word cloud on the tags column for all topics and see the important tags."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "24027035-3f69-5988-2c21-a9fd1522ccfb"
      },
      "outputs": [],
      "source": [
        "topics_list = ['biology', 'cooking', 'crypto', 'diy', 'robotics', 'travel']\n",
        "\n",
        "for ind, topic in enumerate(topics_list):\n",
        "    tags = np.array(pd.read_csv(\"../input/\"+topic+\".csv\", usecols=['tags'])['tags'])\n",
        "    text = ''\n",
        "    for ind, tag in enumerate(tags):\n",
        "        text = \" \".join([text, tag])\n",
        "    text = text.strip()\n",
        "    \n",
        "    wordcloud = WordCloud(background_color='white', width=600, height=300, max_font_size=50, max_words=40).generate(text)\n",
        "    wordcloud.recolor(random_state=ind*312)\n",
        "    plt.imshow(wordcloud)\n",
        "    plt.title(\"Wordcloud for topic : \"+topic)\n",
        "    plt.axis(\"off\")\n",
        "    plt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "c0f04269-7f45-7cf1-5625-13e04733bc6a"
      },
      "source": [
        "**Wordcloud for topic Biology:**\n",
        "   \n",
        "Let us take a single topic 'biology' and then see how the word clouds from each of the three fields title, content, tags compare with each other."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "77bb82f3-5925-34e0-7c2c-903ae0ec20d4"
      },
      "outputs": [],
      "source": [
        "bio = pd.read_csv(\"../input/biology.csv\")\n",
        "title = np.array(bio['title'])\n",
        "content = np.array(bio['content'])\n",
        "tags = np.array(bio['tags'])\n",
        "\n",
        "# wordcloud for tags #\n",
        "text = ''\n",
        "for ind, tag in enumerate(tags):\n",
        "    text = \" \".join([text, tag])\n",
        "text = text.strip()\n",
        "\n",
        "wordcloud = WordCloud(background_color='white', width=600, height=300, max_font_size=50, max_words=80).generate(text)\n",
        "wordcloud.recolor(random_state=218)\n",
        "plt.imshow(wordcloud)\n",
        "plt.axis(\"off\")\n",
        "plt.title(\"Wordcloud on 'tags' for biology \")\n",
        "plt.show()\n",
        "\n",
        "# wordcloud for title #\n",
        "text = ''\n",
        "for ind, tag in enumerate(title):\n",
        "    text = \" \".join([text, tag])\n",
        "text = text.strip()\n",
        "\n",
        "stop_words = set(stopwords.words('english') + ['sas', 'ss', 'fas', 'des', 'les', 'ess'])\n",
        "wordcloud = WordCloud(background_color='white', width=600, height=300, stopwords=stop_words, max_font_size=50, max_words=80).generate(text)\n",
        "wordcloud.recolor(random_state=218)\n",
        "plt.imshow(wordcloud)\n",
        "plt.axis(\"off\")\n",
        "plt.title(\"Wordcloud on 'title' for biology \")\n",
        "plt.show()\n",
        "\n",
        "### Commenting this out for now as it throws error while rendering and not while running it at the backend ###\n",
        "## wordcloud for content #\n",
        "#text = ''\n",
        "#for ind, tag in enumerate(content):\n",
        "#    text = \" \".join([text, tag])\n",
        "#text = text.strip()\n",
        "\n",
        "#stop_words = set(stopwords.words('english') + ['rbs', 'sas', 'ss', 'fas', 'des', 'ess', 'les', 'bas', 'poses', 'los', 'ros', 'cs'])\n",
        "#wordcloud = WordCloud(background_color='white', width=600, height=300, stopwords=stop_words, max_font_size=50, max_words=80).generate(text)\n",
        "#wordcloud.recolor(random_state=218)\n",
        "#plt.imshow(wordcloud)\n",
        "#plt.axis(\"off\")\n",
        "#plt.title(\"Wordcloud on 'content' for biology \")\n",
        "#plt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "6948ea6a-2d00-f199-e4ef-a761f640021e"
      },
      "source": [
        "As we can see, wordcloud from 'topic' is decent and has some important words related to the topic and can be used for tag creation.\n",
        "\n",
        "Wordcloud from 'content' has more irrelevant (html) words and so we need to do proper cleaning to remove those before we start with our modeling / learning.\n",
        "\n",
        "More to come...!"
      ]
    }
  ],
  "metadata": {
    "_change_revision": 0,
    "_is_fork": false,
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.5.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
